//
//  HWSheZhiViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/10/26.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWSheZhiViewController.h"
#import "HWSetUpZhongXingTableViewCell.h"
#import "HWTongYongSheZhiViewController.h" // 通用设置
#import "HWXiaoXiSheViewController.h"
#import "HWXiaoXiSheViewController.h" // 消息设置
#import "HWAboutUsGuanYuViewController.h" // 关于我们
#import "HWWebViewGameViewController.h" // 隐私政策
#import "HWLoginController.h"
#import "HWVersionBouncedView.h"


@interface HWSheZhiViewController ()<UITableViewDataSource,UITableViewDelegate>


@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) NSArray *arr1;
@property(strong,nonatomic) NSArray *arr2;
@property(strong,nonatomic) NSArray *title1Arr;
@property(strong,nonatomic) NSArray *title2Arr;
@property(strong,nonatomic) HWVersionBouncedView *versionBounCeView;
@property(strong,nonatomic) NSDictionary *dataDic;
@end

@implementation HWSheZhiViewController



-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.backgroundColor = RGB(247, 247, 247);
        
    }
    return   _mainaTableVie ;

}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self navigationView];
    [self setupUI];

    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];

}

- (void)navigationView {
    
    self.navigationItem.title = @"设置中心";
    self.navigationItem.title  = [HWjianzhiduiObject keylocalization:@"设置中心"];
    
    self.arr1 = @[@"tongyongshezhi",@"xiaoxishezhi"];
    self.arr2 = @[@"yingsezhengce",@"yingsezhengce",@"banbengenxing",@"guanyuwomen",@"yingsezhengce"];
    
    
  //  self.title1Arr = @[@"通用设置",@"消息设置"];
    
    
    self.title1Arr = @[[HWjianzhiduiObject keylocalization:@"通用设置"],[HWjianzhiduiObject keylocalization:@"消息设置"]];
    
   //  self.title2Arr = @[@"隐私政策",@"版本更新",@"关于我们"];
    
    self.title2Arr =  @[[HWjianzhiduiObject keylocalization:@"隐私政策"],[HWjianzhiduiObject keylocalization:@"用户协议"],[HWjianzhiduiObject keylocalization:@"版本更新"],[HWjianzhiduiObject keylocalization:@"关于我们"],@"账号注销"];
    
    
}



- (void)setupUI {
    
    self.view.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.mainaTableVie];
}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return  2;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    if (section == 0 ) {
        
        return  self.arr1.count;
         
    } else {
        
        return  self.arr2.count;
        
        
    }
     
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *cellID = @"cellID";
    HWSetUpZhongXingTableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    
    
    if (!cell) {
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWSetUpZhongXingTableViewCell" owner:nil options:nil].firstObject;
    
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    if (indexPath.section == 0 ) {
        
        cell.tubiao.image = [UIImage imageNamed:self.arr1[indexPath.row]];
        cell.miaoshuLabel.text = [NSString stringWithFormat:@"%@",self.title1Arr[indexPath.row]];
             
    } else {
        
        cell.tubiao.image = [UIImage imageNamed:self.arr2[indexPath.row]];
        cell.miaoshuLabel.text = [NSString stringWithFormat:@"%@",self.title2Arr[indexPath.row]];
            
    }
    
    
    
    if ( indexPath.row ==  0 ) {
        cell.shangView.hidden = YES;
        
    } else {
        
         cell.shangView.hidden = NO;
        
    }
    
    
    if (indexPath.section == 0 && indexPath.row == 1 ) {
         cell.xiaView.hidden = YES;
    } else if (indexPath.row == 2) {
        
          cell.xiaView.hidden = YES;
        
    } else {
        
         cell.xiaView.hidden = NO;
    }
    
    
    
    return  cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  55;
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    return  10;
    
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    
    
    return 1;
    
    
    
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    UIView *view1 = [[UIView alloc]init];
    view1.backgroundColor = RGB(247, 247, 247);
    return view1;
    
    
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
       UIView *view2 = [[UIView alloc]init];
       view2.backgroundColor = RGB(247, 247, 247);
       return view2;
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
     
    
    if(indexPath.section == 0) {
        
        if (indexPath.row == 0 ) {
            
            
            HWTongYongSheZhiViewController *tongyong = [[HWTongYongSheZhiViewController alloc]init];
            [self.navigationController pushViewController:tongyong animated:YES];
            

        } else if (indexPath.row == 1) {
            
            HWXiaoXiSheViewController *xiaoxi = [[HWXiaoXiSheViewController alloc]init];
            [self.navigationController pushViewController:xiaoxi animated:YES];
            
            
            
            
        }
        
        
        
    } else if (indexPath.section == 1) {
        
        
        if (indexPath.row == 0 ) {
            
            
            HWWebViewGameViewController *webview = [[HWWebViewGameViewController alloc]init];
            webview.urlString = [NSString stringWithFormat:@"%@?ct=zhanwu&ac=agreement&id=2&language=%@",[HWOCGlobalConst baseUrl],[HWjianzhiduiObject returnLanguageAcquisition]];
            webview.gname =@"隐私协议";
            webview.gname = [HWjianzhiduiObject keylocalization:@"隐私协议"];
            webview.isPush = YES;
//            webview.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webview animated:YES];
                  
        
        } else if (indexPath.row == 1) {
            HWWebViewGameViewController *webview = [[HWWebViewGameViewController alloc]init];
            webview.urlString = [NSString stringWithFormat:@"%@?ct=zhanwu&ac=agreement&id=1&language=%@",[HWOCGlobalConst baseUrl],[HWjianzhiduiObject returnLanguageAcquisition]];
            webview.gname = [HWjianzhiduiObject keylocalization:@"用户协议"];
            webview.isPush = YES;
//            webview.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webview animated:YES];
        }else if (indexPath.row == 2) {
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
            NSDictionary *parametes = @{
                @"ct" :  @"app",
                @"ios" : @"1",
                @"ac" : @"isupdate",
                @"versionCode":appCurVersionNum,
                @"member_id":[HWLocallyStoredData getCode],
            };

            [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                
                [SVProgressHUD dismiss];

                NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                if ([codeStr intValue] == 1) {
                    self.dataDic = response[@"data"];
                    [self shiforios_versionCode:response[@"data"][@"ios_versionCode"]];
                }
                
                NSLog(@"%@",response);

            } failure:^(NSString *error) {
                [SVProgressHUD dismiss];

            }];
                 
        }  else if (indexPath.row == 3) {
            NSDictionary *parametes = @{
                @"ct" :  @"app",
                @"ac" : @"contact",
                @"ios" : @"1",
                @"member_id":[HWLocallyStoredData getCode],
                @"h5":@"1",
                @"version":[NSString stringWithFormat:@"%@(%@)",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]
                
            };
            NSArray *allKeys = [parametes allKeys];
            NSArray *allValues = [parametes allValues];
            NSString *logUrl = @"";
            for (int i = 0; i < allKeys.count; i ++) {
                if (i == 0) {
                    logUrl = [NSString stringWithFormat:@"%@?%@=%@",[HWOCGlobalConst baseUrl],allKeys[i],allValues[i]];
                } else {
                    logUrl = [NSString stringWithFormat:@"%@&%@=%@",logUrl,allKeys[i],allValues[i]];
                }
            }
            
            XMGWebViewController *webVC = [[XMGWebViewController alloc] init];
            webVC.url = [NSURL URLWithString:logUrl];
            [self.navigationController pushViewController:webVC animated:YES];

        } else if (indexPath.row == 4)  {
            
            if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
                        
                
                HWLoginController  *login = [[HWLoginController alloc]init];
                [self.navigationController pushViewController:login animated:YES];
                return;
                
                
                     
           }
              
            
            
            NSString *uid = [HWLocallyStoredData getLoginUserID];
            NSString *tString = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
          //  NSString *gidStr = [NSString stringWithFormat:@"%@",self.gameId];
            NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tString,@"fsd213ewdsadqwe2121213edsad"];
            NSString *signMD5 = [WMUtil md5HexDigest:signStr];
            
            HWWebViewGameViewController *webview = [[HWWebViewGameViewController alloc]init];
            webview.urlString = [NSString stringWithFormat:@"%@?ct=zhanwu&ac=userdelete&uid=%@&t=%@&sign=%@",[HWOCGlobalConst baseUrl],uid,tString,signMD5];
            webview.gname =@"用户隐私协议";
            webview.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:webview animated:YES];
            
        }
             
        
        
        
    }
    
  //   HWTongYongSheZhiViewController *t
    
}
- (void)shiforios_versionCode:(NSString *)dangqiang {
    
    // CFBundleShortVersionString
    
     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

     NSString *appCurVersionNum = (NSString *)[infoDictionary objectForKey:@"CFBundleVersion"];

     NSLog(@"当前应用版本号码：%@",appCurVersionNum);

    if ([appCurVersionNum  intValue] == [dangqiang intValue] ) {
        [MBProgressHUD showSuccess:@"暂无更新"];
    } else {

        self.versionBounCeView = [[HWVersionBouncedView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
        
        self.versionBounCeView.dataDic  = self.dataDic;
        [self.versionBounCeView refreshData];
        
        [kKeyWindow addSubview:self.versionBounCeView];
 
    }
  
}









@end
